package com.lkd.controller;

import com.lkd.entity.User;
import com.lkd.service.IUserService;
import com.lkd.vo.LoginUserVo;
import com.lkd.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user-service/user")
public class LoginController {

    @Autowired
    private IUserService userService;


//    @PostMapping("/login")
//    public Result login(){
//        LoginUserVo userVo = new LoginUserVo();
//        userVo.setToken("123");
//        return Result.success(userVo);
//    }

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        LoginUserVo loginUserVo = userService.login(user.getLoginName(),user.getPassword());
        if (loginUserVo != null) {
            return Result.success(loginUserVo);
        }else {
            return Result.error("用户名或密码错误");
        }
    }


}
